package com.itlaobing.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;

public class EstablishingStatement {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        String className = EstablishingStatement.class.getName() ;
        Logger logger = Logger.getLogger( className );

        String name = "MySQL" ; // MySQL | Oracle
        String driverClassName = null ;
        String url = null ;
        String username = null ;
        String password = null ;

        name = name.toLowerCase() ;
            switch ( name ) {
                case "mysql":
                    driverClassName = "com.mysql.cj.jdbc.Driver";
                    url = "jdbc:mysql://localhost:3306/itlaobing?serverTimezone=Asia/Shanghai";
                    username = "root";
                    password = "";
                    break;
                case  "oracle":
                    driverClassName = "oracle.jdbc.driver.OracleDriver" ;
                    url = "jdbc:oracle:thin:@localhost:1521:T2081" ;
                    username = "itlaobing" ;
                    password = "itlaobing" ;
                    break;
            default:
                System.exit( 0 ); // 推出JVM
        }

        Class.forName( driverClassName );
        Connection connection = DriverManager.getConnection( url , username , password );
        logger.info( connection.toString() );

        Statement statement = connection.createStatement();
        logger.info( String.valueOf( statement ) );

        statement.close();
        connection.close();

}

}
